package com.g17.virtualpetbackend.service;

import com.g17.virtualpetbackend.entity.Assistant;
import com.g17.virtualpetbackend.entity.Receptionist;
import com.g17.virtualpetbackend.entity.Vet;
import com.g17.virtualpetbackend.entity.Case;
import com.g17.virtualpetbackend.repo.AssistantRepository;
import com.g17.virtualpetbackend.repo.ReceptionistRepository;
import com.g17.virtualpetbackend.repo.VetRepository;
import com.g17.virtualpetbackend.repo.CaseRepository;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudyServiceImpl implements StudyService{
    @Resource
    AssistantRepository assistantRepository;

    @Resource
    ReceptionistRepository receptionistRepository;

    @Resource
    VetRepository vetRepository;

    @Resource
    CaseRepository caseRepository;

    @Override
    public Assistant findAssistantWork(String work) {
        return assistantRepository.findAssistantWork(work);
    }

    @Override
    public List<Receptionist> findQA() {
        return receptionistRepository.findQA();
    }

    @Override
    public Vet findVetPart(String part) {
        return vetRepository.findVetPart(part);
    }

    @Override
    public Map<String,List<Map<String,String>>> getALLCaseStudy() {
        List<Case> caseList = caseRepository.getALLCaseStudy();
        Map<String, List<Map<String, String>>> caseMap = new HashMap<String, List<Map<String, String>>>();

        for (int i = 0; i < caseList.size(); i++) {
            String disease_name = caseList.get(i).getDisease_name();
            String symptom = caseList.get(i).getSymptom();
            String picture = caseList.get(i).getPicture();
            String video = caseList.get(i).getVideo();
            String treatment = caseList.get(i).getTreatment();
            String category = caseList.get(i).getCategory();
            Map<String, String> diseaseMap = new HashMap<String, String>();
            diseaseMap.put("disease_name", disease_name);
            diseaseMap.put("symptom", symptom);
            diseaseMap.put(" picture", picture);
            diseaseMap.put(" video", video);
            diseaseMap.put(" treatment", treatment);

            if (caseMap.containsKey(category)) {
                List<Map<String, String>> diseaseList = caseMap.get(category);
                diseaseList.add(diseaseMap);
                caseMap.replace(category, diseaseList);
            } else {
                List<Map<String, String>> diseaseList = new ArrayList<Map<String, String>>();
                diseaseList.add(diseaseMap);
                caseMap.put(category, diseaseList);
            }
        }
        return caseMap;
    }
}
